/*
 */

package com.railway.news.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.railway.news.service.IMenuManager;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.StringUtils;

import com.railway.common.base.*;
import com.railway.common.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.railway.news.model.*;
import com.railway.news.dao.*;
import com.railway.news.service.*;
import com.railway.news.vo.query.*;

/**
 * @author  jiangcheng
 * @version 1.0
 * @since 1.0
 */


@Service("menuManager")
@Transactional
public class MenuManagerImpl extends BaseManager<Menu,java.lang.String> implements IMenuManager{

	private IMenuDao menuDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setMenuDao(IMenuDao dao) {
		this.menuDao = dao;
	}
	public EntityDao getEntityDao() {
		return (EntityDao)this.menuDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(MenuQuery query) {
		return menuDao.findPage(query);
	}
	@Transactional(readOnly=true)
	public Menu getById(java.lang.String id){
		return super.getById( id);
	}
	@Transactional
	public void removeById(java.lang.String id){
		super.removeById(id);
	}
	
	/** 插入数据 */
	@Transactional
	public void save(Menu entity){
		super.save(entity);
	}
	
	/** 更新数据 */
	@Transactional
	public void update(Menu entity){
		super.update(entity);
	}
	@Transactional(readOnly=true)
	public boolean isUnique(Menu entity, String uniquePropertyNames){
		return super.isUnique( entity, uniquePropertyNames);
	}
	@Transactional(readOnly=true)
	public List<Menu> findAll(){
		return super.findAll();
	}
	@Transactional
	public void saveOrUpdate(Menu entity) {
		super.saveOrUpdate(entity);
	}
	//初始化菜单
	@Transactional
	public void initMenu(Menu entity) {
 
		List<Menu> list=menuDao.findAll();
		Map map = new ConcurrentHashMap();
		//页顶标题
		List<Menu> topTitle=new ArrayList();
		//菜单
		List<Menu> menus=new ArrayList();
		//左侧标题
		List<Menu> leftTitle=new ArrayList();
		//友情链接
		List<Menu> friendLink=new ArrayList();
		
		if(list!=null){
			for(int i=0;i<list.size();i++){
				Menu menu=(Menu)list.get(i);
				if(menu.getLocations()==null){
				}else if(menu.getLocations().equals("topTitle")){
					topTitle.add(menu);
				}else if(menu.getLocations().equals("menus")){
					menus.add(menu);
				}else if(menu.getLocations().equals("leftTitle")){
					leftTitle.add(menu);
				}else if(menu.getLocations().equals("friendLink")){
					friendLink.add(menu);
				}
			}
		}
		
		//递归整理菜单
		menus=StaticMap.getAllChildrenByid(menus);
		
		map.put("topTitle", topTitle);
		map.put("menus", menus);
		map.put("leftTitle", leftTitle);
		map.put("friendLink", friendLink);
		
		StaticMap.SYS_MENU=map;
	}
	
	public List<Menu> findPageList(MenuQuery query){
		return menuDao.findPageList(query);
	}
	
}
